package com.wc.算法提高课.C第三章_图论.负环.观光奶牛;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/17 13:16
 * @description https://www.acwing.com/problem/content/363/
 */
public class Main {
    /**
     * 思路：01规划问题 -> 二分<p>
     * mid 表示答案
     * 答案求 /sum f[i] / /sum t[i] > mid<p>
     * /sum f[i] - /sum t[i] * mid > 0<p>
     * 让点权依附到边权上面, 相当于 /sum (f[i] - t[i] * mid) > 0<p>
     * 等价于求正环
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 5010;
    static double eps = 1e-4;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static double[] dist = new double[N];
    static int[] q = new int[N], f = new int[N], cnt = new int[N];
    static boolean[] st = new boolean[N];
    static int n, m, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) f[i] = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
        }
        double l = 0, r = 1010;
        while (r - l > eps) {
            double mid = (l + r) / 2;
            if (check(mid)) l = mid;
            else r = mid;
        }
        out.printf("%.2f\n", l);
        out.flush();
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static boolean check(double mid) {
        Arrays.fill(dist, 1, n + 1, 0);
        Arrays.fill(st, 1, n + 1, false);
        Arrays.fill(cnt, 1, n + 1, 0);
        int hh = 0, tt = 0;
        for (int i = 1; i <= n; i++) {
            q[tt++] = i;
            st[i] = true;
        }
        while (hh != tt) {
            int t = q[hh++];
            if (hh == N) hh = 0;
            st[t] = false;
            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i];
                if (dist[j] < dist[t] + f[t] - mid * w[i]) {
                    dist[j] = dist[t] + f[t] - mid * w[i];
                    cnt[j] = cnt[t] + 1;
                    if (cnt[j] >= n) return true;
                    if (!st[j]) {
                        q[tt++] = j;
                        if (tt == N) tt = 0;
                        st[j] = true;
                    }
                }
            }
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
